package io.seata.sample.util.globalId;

import java.util.HashSet;
import java.util.Set;

/**
 * @author By ZengPeng
 * @Description
 * @date in  2021/3/8 16:39
 * @Modified By
 */
public class 雪花test {

    public static void main(String[] args) {
        //单例模式，工作id：这里可以通过配置中心管理
        SnowFlakeGenerateIdWorker snowFlakeGenerateIdWorker =
                new SnowFlakeGenerateIdWorker(0L,0L);

        int i=100;//循环生成1w个无重复
        Set<String> data = new HashSet<>();
        long star = System.currentTimeMillis();
        while (--i>0) {
            String id = snowFlakeGenerateIdWorker.generateNextId();


            if(!data.add(id)){
                System.out.println(data);
                System.out.println("fail");
            }
            System.out.println(id);
        }
        System.out.println("ok! 耗时:"+(System.currentTimeMillis()-star));
    }
}
